﻿@using KPIS.GERP.Models.ICM
@model KPIS.GERP.Models.ICM.File
@{
    Layout = "~/Views/Shared/_EmptyLayout.cshtml";
    ViewBag.Title = "เอกสารแนบ";
    ViewBag.Descr = "เพิ่มข้อมูล" + ViewBag.Title;
    if(Model != null){
        ViewBag.Id = Model.RefId;
        ViewBag.Type = Model.RefType;
    }
}

@using (Html.BeginForm("Create", "File", FormMethod.Post, new { enctype = "multipart/form-data" , @class = "form-horizontal"}))
{
    @Html.AntiForgeryToken()
    
    <div class="span12">
        <div class="block-button-menu-above">
            <a class="btn button-standard-width btn-small btn-gray" data-rel="tooltip" 
                href="@Url.Action("Index", "File", new {id=Model.RefId, type=Model.RefType})" 
                role="button"><i class="icon-reply bigger-120"></i>&nbsp;&nbsp;กลับไปหน้าแสดงข้อมูลทั้งหมด</a>
            @Html.ButtonSubmit()
        </div>
    </div>
        @Html.ValidationSummary(true, KPIS.GERP.Models.Class.ValidateText.RequiredField +(ViewData["file_error"]!=null ? ",  ":"")+ ViewData["file_error"], new { @class = "alert alert-error" })
  
    @Html.Partial("_EditForm")
}

@section scripts
{
    <script>
        $('#file').on("change", function () {
            var fileObj = $('#file');
            var fileNameObj = $('#FileName');
            var FileNameHiddenObj = $('#FileNameHidden');
            var path = fileObj.val();
            var file = path.substr(path.lastIndexOf('\\') + 1);
            
            if (fileNameObj.text() == '') {
                fileNameObj.val(file);
                FileNameHiddenObj.val(file);
            }
        });

        $('#id-input-file-1').ace_file_input({
            no_file: 'No File ...',
            btn_choose: 'Choose',
            btn_change: 'Change',
            droppable: false,
            onchange: null,
            thumbnail: false //| true | large
           // whitelist:'pdf|docx|jpeg'
            //blacklist:'exe|php'
            //onchange:''
            //
        });


        $("form").not("#formsearch").submit(function (e) {
            e.preventDefault();
            var currentForm = this;
            bootbox.confirm("ท่านต้องการยืนยัน ใช่หรือไม่", function (result) {
                if (result) {
                    currentForm.submit();
                }
            });
        });
    </script>
}